<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <title>全局自定义模板</title>
</head>

<body>
    <!--css配置-->
    <style>
        #signin_error {
            display: none;
        }

        #signin_success {
            display: none;
        }

        .signin_result {
            display: flex;
            position: fixed;
            width: 100%;
            height: 100%;
            z-index: 100;
            left: 0;
            top: 0;
            justify-content: center;
            align-items: center;
            flex-flow: column;
            background: #fff;
            font-size: 16px;
        }

        .form-actions {
            display: none !important;
        }

        h3 {
            font-size: 20px;
            margin-top: 18px;
        }
    </style>
    <!--是否加载全局模板 请填写正确的load-template 格式：http://www.xxx.com/-->
    <section id="rootTemplate" load-template=""></section>
    <!--配置API地址 可以覆盖root配置 api-url格式：http://www.xxx.com/-->
    <section id="controller" api-url=""></section>
    <!--RootToolbar配置-->
    <section id="toolbar">
    </section>
    <!--Template配置 key是唯一标识，请不要修改已保证页面正常运行-->
    <section type="template" id="template">
        <a-row>
            <a-col>
                <a-title key="2031553138518968" data-name="会议签到表"></a-title>
            </a-col>
        </a-row>
        <a-row>
            <a-col>
                <a-create-by key="creater" data-name="签到人"></a-create-by>
            </a-col>
        </a-row>
        <a-row>
            <a-col>
                <a-create-by-org key="createdDeptId" data-name="所属部门"></a-create-by-org>
            </a-col>
        </a-row>
        <a-row>
            <a-col>
                <a-created-time key="createdTime" data-name="签到时间" data-format="YYYY-MM-DD HH:mm"></a-created-time>
            </a-col>
        </a-row>
        <a-row>
            <a-col>
                <a-association-form key="meeting" data-name="会议" data-query-code="meeting_notice"
                    data-schema-code="meeting_notice"></a-association-form>
            </a-col>
        </a-row>

        <div id="signin_error" class="signin_result">
            <img src="" />
            <h3>签到失败</h3>
            <div id="signin_error_msg"></div>
        </div>

        <div id="signin_success" class="signin_result">
            <img src="" />
            <h3>签到成功</h3>
        </div>
    </section>
    <!--自定义事件配置-->
    <script id="customScript">
        (function (form) {
            /**
             * 用户自定义JS区域
             */
            /**
             * 事件绑定，form.on
             * @param eventType 事件类型
             * @params function 事件
             * @param  cover    true, false 是否覆盖root的生命周期 默认不覆盖
             */
            //数据加载后，渲染之前
            form.on('onLoad', function (data) {

                const codes = ['save','submit'];

                this.actions.filter(ac => codes.indexOf(ac.code) > -1)
                    .forEach(ac => ac.visible = false);


            }, 'cover');

            form.on('onRendered', function (data) {

                var meetingId = this.$router.currentRoute.query.meetingId;
                if (!meetingId) {
                    this.$message.error('缺少meetingId', 3);
                    return;
                }

                this.meeting.value = {
                    id: meetingId
                };

                var showError = (msg) => {
                    var doc = window.parent.document;
                    var div = doc.getElementById('signin_error');
                    if (div) {
                        div.querySelector('img').src = '/custom/error2.png';
                        var $msg = doc.getElementById('signin_error_msg');
                        $msg.innerText = msg;
                        div.style.display = 'flex';
                    }
                };

                var hideLoading = this.$message.loading();

                var url = env.apiHost + '/api/meeting/validate?meetingId=' + meetingId;

                axios.get(url).then(res => {
                    hideLoading();

                    if (res.errcode !== 0) {
                        this.$message.error(res.errmsg, 3);
                        return;
                    }

                    var result = res.data.result;
                    if (!result) {
                        showError(res.data.info);
                        return;
                    }

                    this.submit();
                });
            });

            //内置校验完成后，返回false阻止提交
            form.on('onValidate', function (action, data) { });
            //操作前执行，返回false阻止按钮操作
            form.on('onPreAction', function (action, data) { });
            //操作后执行
            form.on('onActionDone', function (action, data, res) {
                if (action.code === 'submit') {
                    // if (window.hideLoading) {
                    //     window.hideLoading();
                    // }

                    if (res.errcode === 0) {
                        var div = window.parent.document.getElementById('signin_success');
                        if (div) {
                            div.querySelector('img').src = '/custom/success2.png';
                            div.style.display = 'flex';
                        }
                    } else {
                        this.$message.error(res.errmsg, 3);
                    }
                    return false;
                }
            });
        })
    </script>
    <script type="text/javascript" src="/admin/js/chunk-vendors.js" class="templateScript"></script>
    <script type="text/javascript" src="/admin/js/template.js" class="templateScript"></script>
</body>

</html>
